define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'project/train/index',
                    add_url: 'project/train/add',
                    edit_url: 'project/train/edit',
                    del_url: 'project/train/del',
                    multi_url: 'project/train/multi',
                    table: 'project_train',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                showColumns: false,
                showExport: false,
                showToggle: false,
                commonSearch: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),visible: false},
                        {field: 'unitlist.unit_name', title: __('Unitlist.unit_name'), operate: 'LIKE'},
                        {field: 'project_sn', title: __('Project_sn'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'companycontacts.name', title: __('Companycontacts.name'), operate: 'LIKE'},
                        {field: 'project_type', title: __('Project_type'), operate: 'LIKE'},
                        {field: 'admin.nickname', title: __('大区经理'), operate: 'LIKE'},
                        {field: 'amount', title: __('Amount'), operate: 'BETWEEN'},
                        {field: 'teacher.name', title: __('Teacher_id')},
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {
                                "1": __('Status 1'),
                                "2": __('Status 2'),
                                "3": __('Status 3'),
                                "4": __('Status 4'),
                                "5": __('Status 5'),
                                "6": __('Status 6'),
                                "7": __('Status 7')
                            },
                            formatter: Table.api.formatter.status
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'addtabs',
                                    text: __('培训详情'),
                                    title: __('培训详情'),
                                    classname: 'btn btn-xs  btn-warning btn-addtabs',
                                    icon: 'fa fa-folder-o',
                                    hidden: function (row) {
                                        // if(Config.is_topic != 1){
                                        //     return true;
                                        // }
                                    },
                                    url: function (row) {
                                        return 'project/train/train/project_id/' + row.id;
                                    },
                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        //多表格配置
        all_expand: function () {
            // 初始化表格参数配置
            Table.api.init();
            //绑定事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                var panel = $($(this).attr("href"));
                if (panel.size() > 0) {
                    Controller.table[panel.attr("id")].call(this);
                    $(this).on('click', function (e) {
                        $($(this).attr("href")).find(".btn-refresh").trigger("click");
                    });
                }
                //移除绑定的事件
                $(this).unbind('shown.bs.tab');
            });
            //必须默认触发shown.bs.tab事件
            $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");


            $(document).on('click', '.import_expand', function (event) {
                console.log(1)
                var url = $(this).attr('data-url');
                if (!url) return false;
                var msg = $(this).attr('data-title');
                var width = $(this).attr('data-width');
                var height = $(this).attr('data-height');
                var area = [$(window).width() > 800 ? (width ? width : '800px') : '95%', $(window).height() > 600 ? (height ? height : '600px') : '95%'];
                var options = {
                    shadeClose: false,
                    shade: [0.3, '#393D49'],
                    area: area,
                    callback: function (value) {
                        CallBackFun(value.id, value.name);//在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
                    }
                };
                Fast.api.open(url, msg, options);
            });
            //批量收回、批量分配、批量删除
            $(document).on('click', '.allocation_expand', function (event) {
                var table_name = $(this).attr('data-table');
                var ids = Table.api.selectedids($("#"+table_name));
                var url = $(this).attr('data-url');
                if (!url) return false;
                if (ids.length == 0) {
                    Layer.alert('请选择线索')
                    return true;
                }
                url = url + '/ids/' + ids.join(",");
                console.log(url)
                var msg = $(this).attr('data-title');
                var width = $(this).attr('data-width');
                var height = $(this).attr('data-height');
                var area = [$(window).width() > 800 ? (width ? width : '800px') : '95%', $(window).height() > 600 ? (height ? height : '600px') : '95%'];
                var options = {
                    shadeClose: false,
                    shade: [0.3, '#393D49'],
                    area: area,
                    callback: function (value) {
                        CallBackFun(value.id, value.name);//在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
                    }
                };
                Fast.api.open(url, msg, options);
            });
            //批量认领
            $(document).on('click', '.allocation_claim', function (event) {
                var table_name = $(this).attr('data-table');
                var ids = Table.api.selectedids($("#"+table_name));
                var url = $(this).attr('data-url');
                if (!url) return false;
                if (ids.length == 0) {
                    Layer.alert('请选择线索')
                    return true;
                }
                url = url + '/ids/' + ids.join(",");
                Layer.confirm('确定认领？', {
                    btn: ['确认','取消'] //按钮
                }, function(index){
                    $.ajax({
                        url:url,
                        data:'',
                        success:function (data) {
                            if(data.code ===1){
                                Toastr.success(data.msg);
                                $(".btn-refresh").trigger("click");
                            }else{
                                Layer.alert(data.msg)
                            }
                        }
                    });
                    Layer.close(index);
                    return true;
                }, function(index){
                    Layer.close(index);
                    return false;
                });


            });

            //批量还原、彻底删除
            $(document).on('click', '.allocation_restore', function (event) {
                var ids = Table.api.selectedids($("#recovery_table"));
                var url = $(this).attr('data-url');
                if (!url) return false;
                if (ids.length == 0) {
                    Layer.alert('请选择线索')
                    return true;
                }
                url = url + '/ids/' + ids.join(",");
                console.log(url)
                var msg = $(this).attr('data-title');
                var width = $(this).attr('data-width');
                var height = $(this).attr('data-height');
                var area = [$(window).width() > 800 ? (width ? width : '800px') : '95%', $(window).height() > 600 ? (height ? height : '600px') : '95%'];
                var options = {
                    shadeClose: false,
                    shade: [0.3, '#393D49'],
                    area: area,
                    callback: function (value) {
                        CallBackFun(value.id, value.name);//在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
                    }
                };
                Fast.api.open(url, msg, options);
            })
        },
        //多表格配置
        table: {
            all: function () {

            },
            //全部线索
            facilitator: function () {
                var facilitator_table = $("#facilitator_table");
                facilitator_table.bootstrapTable({
                    url: 'facilitator/index' + location.search,
                    extend: {
                        index_url: 'facilitator/index' + location.search,
                        add_url: 'facilitator/add',
                        edit_url: 'facilitator/edit',
                        del_url: 'facilitator/del',
                        multi_url: 'facilitator/multi',
                        import_url: 'facilitator/import',
                        table: 'facilitator',
                    },
                    toolbar: '#facilitator_toolbar',
                    pk: 'id',
                    sortName: 'id',
                    fixedColumns: true,
                    fixdedRightNumber: 1,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'id', title: __('Id'), visible: false},
                            {field: 'title', title: __('Title'), operate: 'LIKE', formatter: Controller.api.formatter.title},
                            {field: 'name', title: __('Name'), operate: 'LIKE'},
                            {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                            // {field: 'identity_sn', title: __('Identity_sn'), operate: 'LIKE'},
                            {field: 'brand.name', title: __('Brand_id'), operate: 'LIKE'},
                            {field: 'area', title: __('Area'), operate: 'LIKE'},
                            {field: 'wechat', title: __('Wechat'), operate: 'LIKE'},
                            {field: 'qq', title: __('Qq'), operate: 'LIKE'},
                            {field: 'email', title: __('Email'), operate: 'LIKE'},
                            {field: 'source.name', title: __('Source'), operate: 'LIKE'},
                            {field: 'introducer', title: __('Introducer'), operate: 'LIKE'},
                            {field: 'intention.name', title: __('Intention'), operate: 'LIKE'},
                            {field: 'admin.nickname', title: __('Serve_id'), operate: 'LIKE'},
                            {
                                field: 'type',
                                title: __('跟进状态'),
                                searchList: {
                                    "0": __('Type 0'),
                                    "1": __('Type 1'),
                                    "2": __('Type 2'),
                                    "3": __('Type 3'),
                                    "4": __('Type 4')
                                },
                                formatter: Table.api.formatter.normal
                            },
                            {field: 'stage.name', title: __('跟进阶段'), operate: 'LIKE'},
                            {field: 'serve_id', title: __('Serve_id'), visible: false},
                            {field: 'address', title: __('Address'), operate: 'LIKE'},
                            {field: 'promote_time', title: __('最后一次跟进时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                            {field: 'plan_time', title: __('下次跟进时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                            {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                            {
                                field: 'operate', title: __('Operate'), table: facilitator_table, buttons: [
                                    {
                                        name: 'follow',
                                        text: '跟进',
                                        title: '跟进',
                                        extend: 'data-area=["70%","70%"]',
                                        classname: 'btn btn-xs btn-primary btn-dialog',
                                        confirm: function (row) {
                                            if (!row.serve_id) {
                                                return '系统将添加你作为此条线索的跟进人。后续的线索跟进将由你负责。'
                                            }
                                            return false
                                        },
                                        url: function (row) {
                                            if (!row.serve_id) {
                                                return 'facilitatorexpand/add/facilitator_id/' + row.id + '/type/2';
                                            }
                                            if (row.have_plan == 1) {
                                                return 'facilitatorexpand/index/facilitator_id/' + row.id;
                                            }
                                            return 'facilitatorexpand/add/facilitator_id/' + row.id + '/type/1';
                                        },
                                    },
                                    {
                                        name: 'change_facilitator',
                                        text: '转为服务商',
                                        title: '转为服务商',
                                        extend: 'data-area=["70%","70%"]',
                                        classname: 'btn btn-xs btn-primary btn-dialog',
                                        url: function (row) {
                                            return 'facilitator/change_true/ids/' + row.id;
                                        },
                                        hidden: function (row) {
                                            if (row.shop_id > 0) {
                                                return true
                                            }
                                            return false
                                        },
                                    },
                                ], events: Table.api.events.operate, formatter: Table.api.formatter.operate
                            }
                        ]
                    ],
                });
                //为表格绑定事件
                Table.api.bindevent(facilitator_table);
            },
            //无跟进人线索
            noserve: function () {
                var noserve_table = $("#noserve_table");
                noserve_table.bootstrapTable({
                    url: 'facilitator/index/serve/0' + location.search,
                    extend: {
                        index_url: 'facilitator/index' + location.search,
                        add_url: 'facilitator/add',
                        edit_url: 'facilitator/edit',
                        del_url: 'facilitator/del',
                        multi_url: 'facilitator/multi',
                        import_url: 'facilitator/import',
                        table: 'facilitator',
                    },
                    toolbar: '#noserve_toolbar',
                    pk: 'id',
                    sortName: 'id',
                    fixedColumns: true,
                    fixedRightNumber: 1,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'id', title: __('Id'), visible: false},
                            {field: 'title', title: __('Title'), operate: 'LIKE'},
                            {field: 'name', title: __('Name'), operate: 'LIKE'},
                            {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                            // {field: 'identity_sn', title: __('Identity_sn'), operate: 'LIKE'},
                            {field: 'brand.name', title: __('Brand_id'), operate: 'LIKE'},
                            {field: 'area', title: __('Area'), operate: 'LIKE'},
                            {field: 'wechat', title: __('Wechat'), operate: 'LIKE'},
                            {field: 'qq', title: __('Qq'), operate: 'LIKE'},
                            {field: 'email', title: __('Email'), operate: 'LIKE'},
                            {field: 'source.name', title: __('Source'), operate: 'LIKE'},
                            {field: 'introducer', title: __('Introducer'), operate: 'LIKE'},
                            {field: 'intention.name', title: __('Intention'), operate: 'LIKE'},
                            {field: 'admin.nickname', title: __('Serve_id'), operate: 'LIKE'},
                            {field: 'serve_id', title: __('Serve_id'), visible: false},
                            {field: 'address', title: __('Address'), operate: 'LIKE'},
                            {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                            {
                                field: 'type',
                                title: __('Type'),
                                searchList: {
                                    "0": __('Type 0'),
                                    "1": __('Type 1'),
                                    "2": __('Type 2'),
                                    "3": __('Type 3'),
                                    "4": __('Type 4')
                                },
                                formatter: Table.api.formatter.normal
                            },
                            {
                                field: 'operate', title: __('Operate'), table: noserve_table, buttons: [
                                    {
                                        name: 'follow',
                                        text: '跟进',
                                        title: '跟进',
                                        extend: 'data-area=["70%","70%"]',
                                        classname: 'btn btn-xs btn-primary btn-dialog',
                                        confirm: function (row) {
                                            if (!row.serve_id) {
                                                return '系统将添加你作为此条线索的跟进人。后续的线索跟进将由你负责。'
                                            }
                                            return false
                                        },
                                        url: function (row) {
                                            if (!row.serve_id) {
                                                return 'facilitatorexpand/add/facilitator_id/' + row.id + '/type/2';
                                            }
                                            if (row.have_plan == 1) {
                                                return 'facilitatorexpand/index/facilitator_id/' + row.id;
                                            }
                                            return 'facilitatorexpand/add/facilitator_id/' + row.id + '/type/1';
                                        },

                                    },
                                    {
                                        name: 'change_facilitator',
                                        text: '转为服务商',
                                        title: '转为服务商',
                                        extend: 'data-area=["70%","70%"]',
                                        classname: 'btn btn-xs btn-primary btn-dialog',
                                        url: function (row) {
                                            return 'facilitator/change_true/ids/' + row.id;
                                        },
                                        hidden: function (row) {
                                            if (row.shop_id > 0) {
                                                return true
                                            }
                                            return false
                                        },
                                    },
                                ], events: Table.api.events.operate, formatter: Table.api.formatter.operate
                            }
                        ]
                    ],
                });
                //为表格绑定事件
                Table.api.bindevent(noserve_table);
            },
            //有跟进人线索
            haveserve: function () {
                var haveserve_table = $("#haveserve_table");
                haveserve_table.bootstrapTable({
                    url: 'facilitator/index/serve/1' + location.search,
                    extend: {
                        index_url: 'facilitator/index' + location.search,
                        add_url: 'facilitator/add',
                        edit_url: 'facilitator/edit',
                        del_url: 'facilitator/del',
                        multi_url: 'facilitator/multi',
                        import_url: 'facilitator/import',
                        table: 'facilitator',
                    },
                    toolbar: '#haveserve_toolbar',
                    pk: 'id',
                    sortName: 'id',
                    fixedColumns: true,
                    fixedRightNumber: 1,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'id', title: __('Id'), visible: false},
                            {field: 'title', title: __('Title'), operate: 'LIKE'},
                            {field: 'name', title: __('Name'), operate: 'LIKE'},
                            {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                            // {field: 'identity_sn', title: __('Identity_sn'), operate: 'LIKE'},
                            {field: 'brand.name', title: __('Brand_id'), operate: 'LIKE'},
                            {field: 'area', title: __('Area'), operate: 'LIKE'},
                            {field: 'wechat', title: __('Wechat'), operate: 'LIKE'},
                            {field: 'qq', title: __('Qq'), operate: 'LIKE'},
                            {field: 'email', title: __('Email'), operate: 'LIKE'},
                            {field: 'source.name', title: __('Source'), operate: 'LIKE'},
                            {field: 'introducer', title: __('Introducer'), operate: 'LIKE'},
                            {field: 'intention.name', title: __('Intention'), operate: 'LIKE'},
                            {field: 'admin.nickname', title: __('Serve_id'), operate: 'LIKE'},
                            {field: 'serve_id', title: __('Serve_id'), visible: false},
                            {field: 'address', title: __('客户地址'), operate: 'LIKE'},
                            {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                            {
                                field: 'type',
                                title: __('Type'),
                                searchList: {
                                    "0": __('Type 0'),
                                    "1": __('Type 1'),
                                    "2": __('Type 2'),
                                    "3": __('Type 3'),
                                    "4": __('Type 4')
                                },
                                formatter: Table.api.formatter.normal
                            },
                            {
                                field: 'operate', title: __('Operate'), table: haveserve_table, buttons: [
                                    {
                                        name: 'follow',
                                        text: '跟进',
                                        title: '跟进',
                                        extend: 'data-area=["70%","70%"]',
                                        classname: 'btn btn-xs btn-primary btn-dialog',
                                        confirm: function (row) {
                                            if (!row.serve_id) {
                                                return '系统将添加你作为此条线索的跟进人。后续的线索跟进将由你负责。'
                                            }
                                            return false
                                        },
                                        url: function (row) {
                                            if (!row.serve_id) {
                                                return 'facilitatorexpand/add/facilitator_id/' + row.id + '/type/2';
                                            }
                                            if (row.have_plan == 1) {
                                                return 'facilitatorexpand/index/facilitator_id/' + row.id;
                                            }
                                            return 'facilitatorexpand/add/facilitator_id/' + row.id + '/type/1';
                                        },

                                    },
                                    {
                                        name: 'change_facilitator',
                                        text: '转为服务商',
                                        title: '转为服务商',
                                        extend: 'data-area=["70%","70%"]',
                                        classname: 'btn btn-xs btn-primary btn-dialog',
                                        url: function (row) {
                                            return 'facilitator/change_true/ids/' + row.id;
                                        },
                                        hidden: function (row) {
                                            if (row.shop_id > 0) {
                                                return true
                                            }
                                            return false
                                        },
                                    },
                                ], events: Table.api.events.operate, formatter: Table.api.formatter.operate
                            }
                        ]
                    ],
                });
                //为表格绑定事件
                Table.api.bindevent(haveserve_table);
            },
            //我的线索
            my: function () {
                var my_table = $("#my_table");
                my_table.bootstrapTable({
                    url: 'facilitator/my_index' + location.search,
                    extend: {
                        index_url: 'facilitator/my_index' + location.search,
                        add_url: 'facilitator/add',
                        edit_url: 'facilitator/edit',
                        del_url: 'facilitator/del',
                        multi_url: 'facilitator/multi',
                        import_url: 'facilitator/import',
                        table: 'facilitator',
                    },
                    toolbar: '#toolbar2',
                    pk: 'id',
                    sortName: 'id',
                    fixedColumns: true,
                    fixedRightNumber: 1,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'id', title: __('Id'), visible: false},
                            {field: 'title', title: __('Title'), operate: 'LIKE'},
                            {field: 'name', title: __('Name'), operate: 'LIKE'},
                            {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                            // {field: 'identity_sn', title: __('Identity_sn'), operate: 'LIKE'},
                            {field: 'brand.name', title: __('Brand_id'), operate: 'LIKE'},
                            {field: 'area', title: __('Area'), operate: 'LIKE'},
                            {field: 'wechat', title: __('Wechat'), operate: 'LIKE'},
                            {field: 'qq', title: __('Qq'), operate: 'LIKE'},
                            {field: 'email', title: __('Email'), operate: 'LIKE'},
                            {field: 'source.name', title: __('Source'), operate: 'LIKE'},
                            {field: 'introducer', title: __('Introducer'), operate: 'LIKE'},
                            {field: 'intention.name', title: __('Intention'), operate: 'LIKE'},
                            {field: 'admin.nickname', title: __('Serve_id'), operate: 'LIKE'},
                            {field: 'serve_id', title: __('Serve_id'), visible: false},
                            {field: 'address', title: __('Address'), operate: 'LIKE'},
                            {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                            {
                                field: 'type',
                                title: __('Type'),
                                searchList: {
                                    "0": __('Type 0'),
                                    "1": __('Type 1'),
                                    "2": __('Type 2'),
                                    "3": __('Type 3'),
                                    "4": __('Type 4')
                                },
                                formatter: Table.api.formatter.normal
                            },
                            {
                                field: 'operate', title: __('Operate'), table: my_table, buttons: [
                                    {
                                        name: 'follow',
                                        text: '跟进',
                                        title: '跟进',
                                        extend: 'data-area=["70%","70%"]',
                                        classname: 'btn btn-xs btn-primary btn-dialog',
                                        confirm: function (row) {
                                            if (!row.serve_id) {
                                                return '系统将添加你作为此条线索的跟进人。后续的线索跟进将由你负责。'
                                            }
                                            return false
                                        },
                                        url: function (row) {
                                            if (row.serve_id == 0) {
                                                return 'facilitatorexpand/add/facilitator_id/' + row.id + '/type/2';
                                            }
                                            if (row.have_plan == 1) {
                                                return 'facilitatorexpand/index/facilitator_id/' + row.id;
                                            }
                                            return 'facilitatorexpand/add/facilitator_id/' + row.id + '/type/1';
                                        },

                                    },
                                    {
                                        name: 'change_facilitator',
                                        text: '转为服务商',
                                        title: '转为服务商',
                                        extend: 'data-area=["70%","70%"]',
                                        classname: 'btn btn-xs btn-primary btn-dialog',
                                        url: function (row) {
                                            return 'facilitator/change_true/ids/' + row.id;
                                        },
                                        hidden: function (row) {
                                            if (row.shop_id > 0) {
                                                return true
                                            }
                                            return false
                                        },
                                    },
                                ], events: Table.api.events.operate, formatter: Table.api.formatter.operate
                            }
                        ]
                    ],
                });
                // 为表格绑定事件
                Table.api.bindevent(my_table);
            },
            //公有池
            pub: function () {
                var pub_table = $("#pub_table");
                pub_table.bootstrapTable({
                    url: 'facilitator/index/is_public/1' + location.search,
                    extend: {
                        index_url: 'facilitator/index' + location.search,
                        add_url: 'facilitator/add',
                        edit_url: 'facilitator/edit',
                        del_url: 'facilitator/del',
                        multi_url: 'facilitator/multi',
                        import_url: 'facilitator/import',
                        table: 'facilitator',
                    },
                    toolbar: '#toolbar3',
                    pk: 'id',
                    sortName: 'id',
                    fixedColumns: true,
                    fixedRightNumber: 1,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'id', title: __('Id'), visible: false},
                            {field: 'title', title: __('Title'), operate: 'LIKE'},
                            {field: 'name', title: __('Name'), operate: 'LIKE'},
                            {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                            // {field: 'identity_sn', title: __('Identity_sn'), operate: 'LIKE'},
                            {field: 'brand.name', title: __('Brand_id'), operate: 'LIKE'},
                            {field: 'area', title: __('Area'), operate: 'LIKE'},
                            {field: 'wechat', title: __('Wechat'), operate: 'LIKE'},
                            {field: 'qq', title: __('Qq'), operate: 'LIKE'},
                            {field: 'email', title: __('Email'), operate: 'LIKE'},
                            {field: 'source.name', title: __('Source'), operate: 'LIKE'},
                            {field: 'introducer', title: __('Introducer'), operate: 'LIKE'},
                            {field: 'intention.name', title: __('Intention'), operate: 'LIKE'},
                            {field: 'admin.nickname', title: __('Serve_id'), operate: 'LIKE'},
                            {field: 'serve_id', title: __('Serve_id'), visible: false},
                            {field: 'address', title: __('Address'), operate: 'LIKE'},
                            {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                            {
                                field: 'type',
                                title: __('Type'),
                                searchList: {
                                    "0": __('Type 0'),
                                    "1": __('Type 1'),
                                    "2": __('Type 2'),
                                    "3": __('Type 3'),
                                    "4": __('Type 4')
                                },
                                formatter: Table.api.formatter.normal
                            },
                            {
                                field: 'operate', title: __('Operate'), table: pub_table, buttons: [
                                    {
                                        name: 'follow',
                                        text: '跟进',
                                        title: '跟进',
                                        extend: 'data-area=["70%","70%"]',
                                        classname: 'btn btn-xs btn-primary btn-dialog',
                                        confirm: function (row) {
                                            if (!row.serve_id) {
                                                return '系统将添加你作为此条线索的跟进人。后续的线索跟进将由你负责。'
                                            }
                                            return false
                                        },
                                        url: function (row) {
                                            if (row.serve_id == 0) {
                                                return 'facilitatorexpand/add/facilitator_id/' + row.id + '/type/2';
                                            }
                                            if (row.have_plan == 1) {
                                                return 'facilitatorexpand/index/facilitator_id/' + row.id;
                                            }
                                            return 'facilitatorexpand/add/facilitator_id/' + row.id + '/type/1';
                                        },

                                    },
                                    {
                                        name: 'change_facilitator',
                                        text: '转为服务商',
                                        title: '转为服务商',
                                        extend: 'data-area=["70%","70%"]',
                                        classname: 'btn btn-xs btn-primary btn-dialog',
                                        url: function (row) {
                                            return 'facilitator/change_true/ids/' + row.id;
                                        },
                                        hidden: function (row) {
                                            if (row.shop_id > 0) {
                                                return true
                                            }
                                            return false
                                        },
                                    },
                                ], events: Table.api.events.operate, formatter: Table.api.formatter.operate
                            }
                        ]
                    ],
                });
                // 为表格绑定事件
                Table.api.bindevent(pub_table);
            },
            //回收站
            recovery: function () {
                var recovery_table = $("#recovery_table");
                recovery_table.bootstrapTable({
                    url: 'facilitator/recyclebin' + location.search,
                    extend: {
                        index_url: 'facilitator/recyclebin' + location.search,
                        add_url: 'facilitator/add',
                        edit_url: 'facilitator/edit',
                        del_url: 'facilitator/del',
                        multi_url: 'facilitator/multi',
                        import_url: 'facilitator/import',
                        table: 'facilitator',
                    },
                    toolbar: '#toolbar4',
                    pk: 'id',
                    sortName: 'id',
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'id', title: __('Id'), visible: false},
                            {field: 'title', title: __('Title'), operate: 'LIKE'},
                            {field: 'name', title: __('Name'), operate: 'LIKE'},
                            {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                            {field: 'source.name', title: __('Source'), operate: 'LIKE'},
                            {field: 'createtime', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                            {field: 'deladmin.nickname', title: __('删除人'), operate: 'LIKE'},
                            {field: 'deletetime', title: __('删除时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                            {
                                field: 'operate', title: __('Operate'), table: recovery_table, events: Table.api.events.operate, formatter: Table.api.formatter.operate
                            }
                        ]
                    ],
                });
                // 为表格绑定事件
                Table.api.bindevent(recovery_table);
            },
        },
        //批量删除
        delete_expand: function () {
            Controller.api.bindevent();
        },
        //批量导入
        import_expand: function () {
            Controller.api.bindevent();
        },
        //批量分配
        allocation_expand: function () {
            $("input[name='row[type]']").change(function () {
                console.log(this.value)
                if (this.value == 1) {
                    $('#no_public').show()
                } else {
                    $('#no_public').hide()
                }
            })
            //搜索跟进人
            $('.search').click(function () {
                var name = $('#name').val()
                get_admin(name)
            })
            get_admin('')

            //获取招商人员
            function get_admin(name) {
                $.ajax({
                    url: '/admin/facilitator/admin_list',
                    data: {name: name},
                    success: function (data) {
                        console.log(data);
                        if (data.code === 1) {
                            add_memberlist(data.data.rows)
                        }
                    }
                });
            }

            //分配人
            function add_memberlist(data) {
                var html = '';
                for (var i = 0; i < data.length; i++) {
                    var html1 = `
                        <tr data-index="0" class="selected u_list1" style=""> 
                            <td class="bs-checkbox ">
                                <input data-index="0" name="row[uid]" type="radio" value="` + data[i].id + `">
                            </td> 
                            <td style="text-align: center; vertical-align: middle; ">` + data[i].nickname + `</td> 
                            <td style="text-align: center; vertical-align: middle; ">` + data[i].nickname + `</td> 
                            <td style="text-align: center; vertical-align: middle; ">` + data[i].num + `</td> 
                        </tr>
                    `;
                    html = html + html1;
                }
                $('.u_list1').remove()
                $('.u_list').append(html)
            }

            Controller.api.bindevent();
        },
        change_true: function () {
            $(function () {
                $('#myTab a').click(function () {
                    $(this).tab('show')
                })
            })
            var html = `
                <div style="border: 1px solid grey;margin: 10px 10%;position: relative;">
                    <img style="width:16px;position: absolute;top: -8px;right: -8px;padding: 3px;background: rgba(0,0,0,0.4);border-radius: 50%;" class="close_icon" src="/assets/img/close11.png" />
                    <div class="form-group" style="margin-top:10px">
                        <label class="control-label col-xs-12 col-sm-2">类型</label>
                        <div class="col-xs-12 col-sm-8">        
                            <select  id="c-bank_type" class="form-control selectpicker bank_type" name="row[bank_type][]">
                                <option value="1" selected>个人</option>
                                <option value="2" >企业</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2 bank_name">姓名:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-bank_name" class="form-control" name="row[bank_name][]" type="text" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2 bank_no">身份证号:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-bank_card_no" class="form-control" name="row[bank_card_no][]" type="text" >
                        </div>
                    </div>
                    <input type="hidden" name="row[bank_id][]" value="">
                </div>`
            // 添加周几时间
            $('.add_bank').click(function () {
                $(".bank_list").append(html);
                Form.api.bindevent($("form[role=form]"));
            })
            $(document).on("change", ".bank_type", function () {
                var bank_name = '姓名'
                var bank_no = '身份证号'
                console.log(this.value)
                if (this.value == '1') {
                    bank_name = '姓名'
                    bank_no = '身份证号'
                } else {
                    bank_name = '公司名称'
                    bank_no = '机构代码'
                }
                console.log(bank_name)
                $(this).parent().parent().parent().next().find('.bank_name').html(bank_name);
                $(this).parent().parent().parent().next().next().find('.bank_no').html(bank_no);
            })
            $(".close_icon").click(function(){
                $(this).parent().remove();
            });
            Controller.api.bindevent();
        },
        allocation_restore: function () {
            Controller.api.bindevent();
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {

                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {//渲染的方法
                title: function (value, row, index) {
                    return '<a class="btn-addtabs" href="/ssphp.php/facilitatorexpand/facilitator/facilitator_id/'+row.id+'"> ' +value + '</a>';
                },
                property: function (value, row, index) {
                    if(row.members.name !=""){
                        return  row.members.nickname+"（"+row.members.name+"）";
                    }else {
                        return  row.members.nickname;
                    }

                },
            },

        }
    };
    return Controller;
});
